package com.aoxin.service.impl.opm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.opm.SlfClassroomMapper;
import com.aoxin.mapper.opm.SlfSyllabusDateMapper;
import com.aoxin.model.opm.SlfSyllabusDate;
import com.aoxin.service.inter.opm.SyllabusDateService;
import com.aoxin.util.ErrorUtil;

@Service("syllabusDateService")
public class SyllabusDateServiceImpl implements SyllabusDateService {

	@Autowired
	private SlfSyllabusDateMapper slfSyllabusDateMapper;

	@Autowired
	private SlfClassroomMapper slfClassroomMapper;

	@Override
	@Transactional
	public void insertSlfSyllabusDate(SlfSyllabusDate syllabusDate) {
		Assert.notNull(syllabusDate, String.format(ErrorUtil.PARAMETER_NULL, "syllabusDate"));
		this.slfSyllabusDateMapper.insertSelective(syllabusDate);
	}

	@Override
	@Transactional
	public void deleteSlfSyllabusDateByIds(List<Integer> syllabusDateIds) {
		Assert.notEmpty(syllabusDateIds, String.format(ErrorUtil.PARAMETER_NULL, "syllabusDateIds"));
		Map<String, Object> map = new HashMap<String, Object>();
		for (Integer integer : syllabusDateIds) {
			map.put("syllabusDateId", integer);
			if (this.slfClassroomMapper.getRecordCount(map) > 0L) {
				throw new IllegalArgumentException(ErrorUtil.SYLLABUS_DATE);
			}
		}
		this.slfSyllabusDateMapper.deleteByPrimaryKeys(syllabusDateIds);
	}

	@Override
	@Transactional
	public void updateSlfSyllabusDate(SlfSyllabusDate syllabusDate) {
		Assert.notNull(syllabusDate, String.format(ErrorUtil.PARAMETER_NULL, "syllabusDate"));
		this.slfSyllabusDateMapper.updateByPrimaryKeySelective(syllabusDate);
	}

	@Override
	@Transactional
	public void updateSlfSyllabusDateStates(List<Integer> syllabusDateIds, Integer state) {
		Assert.notEmpty(syllabusDateIds, String.format(ErrorUtil.PARAMETER_NULL, "syllabusDateIds"));
		this.slfSyllabusDateMapper.updateStates(syllabusDateIds, state);
	}

	@Override
	public SlfSyllabusDate getSlfSyllabusDate(Integer syllabusDateId) {
		Assert.notNull(syllabusDateId, String.format(ErrorUtil.PARAMETER_NULL, "syllabusDateId"));
		return this.slfSyllabusDateMapper.selectByPrimaryKey(syllabusDateId);
	}

	@Override
	public List<SlfSyllabusDate> getSlfSyllabusDateList(Map<String, Object> params) {
		return this.slfSyllabusDateMapper.getList(params);
	}

	@Override
	public List<SlfSyllabusDate> getSelectList(Integer classroomId) {
		return this.slfSyllabusDateMapper.getSelectList(classroomId);
	}

}
